package com.nidu.demo.company.executor.query;

import com.alibaba.cola.dto.PageResponse;
import com.nidu.demo.company.convertor.CompanyConvertor;
import com.nidu.demo.company.convertor.CompanyCriteriaConvertor;
import com.nidu.demo.company.dto.CompanyCO;
import com.nidu.demo.company.dto.CompanyPageQry;
import com.nidu.demo.company.gateway.CompanyGateway;
import com.nidu.demo.company.model.Company;
import com.nidu.demo.company.model.CompanyCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 公司分页查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class CompanyPageQryExe {

    private final CompanyGateway gateway;

    private final CompanyConvertor convertor;

    private final CompanyCriteriaConvertor criteriaConvertor;

    public PageResponse<CompanyCO> execute(CompanyPageQry qry) {
        CompanyCriteria criteria = criteriaConvertor.toDataObject(qry);
        PageResponse<Company> page = gateway.pageByCondition(criteria);
        List<CompanyCO> companyCOS = convertor.toClientObjects(page.getData());
        return PageResponse.of(companyCOS, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
    }
}